package com.gxuwz.medical.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxuwz.medical.domain.person.Person;

public class PersonServlet extends BaseServlet{
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String m =req.getParameter("m");
		if("list".equals(m)){
		  	process(req, resp, "/page/person/person_list.jsp");
		}else if("get".equals(m)){
			process(req, resp, "/page/person/person_edit.jsp");
		}else if("move".equals(m)){
			process(req, resp, "/page/person/person_list.jsp");
		}else if("edit".equals(m)){
			edit(req, resp);
		}else if("del".equals(m)){
			del(req, resp);
		}
		
	}
	/**
	 * 
	 * @param req
	 * @param resp
	 * @throws ServletException
	 * @throws IOException
	 */
	/**
	 * 
	 * @param req
	 * @param resp
	 * @throws ServletException
	 * @throws IOException
	 */
	private void edit(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{

	  	  //1获取值
	  	  String persCode=req.getParameter("persCode");
	  	  String persName=req.getParameter("persName");
	  	  String sex=req.getParameter("sex");
	  	  String birthday=req.getParameter("birthday");
	  	  String persPro=req.getParameter("persPro");
	  	  String occupation=req.getParameter("occupation");
	  	  String workUnit=req.getParameter("workUnit");
	  	  String liveAddress=req.getParameter("liveAddress");
	  	  String telephone=req.getParameter("telephone");
	  	  
	  	  Person person=new Person(persCode, persName,sex,birthday,persPro,occupation,workUnit,liveAddress,telephone);
	  	
	  	  try{
	  		person.edit();
	  		process(req, resp, "/page/person/person_list.jsp");
	  	  }catch(Exception e){
	  		e.printStackTrace();
	  	  }
		
	  
		}
	private void del(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{

	  	
	  	  String persCode=req.getParameter("persCode");
	  	  
	  	  Person person=new Person();
	  	  try{
	  		System.out.println(persCode);
	  		person.del(persCode);
	  		process(req, resp, "/page/person/person_list.jsp");
	  	  }catch(Exception e){
	  		e.printStackTrace();
	  	  }
	  
		}

}
